package org.ihelpuoo.lang;

public class BooleanUtils
{
	public static boolean parseBoolean(String v)
	{
		if (null == v)
			return false;
		v = StringUtils.trim(v);
		v = v.toLowerCase();
		if ("1".equals(v))
			return true;
		if ("y".equals(v))
			return true;
		if ("on".equals(v))
			return true;
		if ("yes".equals(v))
			return true;
		if ("true".equals(v))
			return true;
		return false;
	}

	public static boolean isTrue(Object obj)
	{
		if (null == obj)
			return false;
		Class type = obj.getClass();
		if (ObjectUtils.isBoolean(type))
			return ((Boolean)obj).booleanValue();
		if (ObjectUtils.isInteger(type))
			return ((Integer)obj).intValue() > 0;
		return !"false".equalsIgnoreCase(obj.toString());
	}
}
